package com.bysj.service.impl;

import java.util.ArrayList;

import com.bysj.dao.ManagerDao;
import com.bysj.dao.impl.ManagerDaoImpl;
import com.bysj.entity.Manager;
import com.bysj.service.ManagerService;

public class ManagerServiceImpl implements ManagerService{
	private ManagerDao md=new ManagerDaoImpl();
	@Override
	public void addManager(Manager manager) {
		String sql="insert into manager(name,age,tel,email,passwd,pic,umanager,amanager,bmanager,rmanager,gmanager,nmanager) values(?,?,?,?,?,?,?,?,?,?,?,?)";
		md.addManager(sql, manager);
	}

	@Override
	public void delManager(Manager manager) {
		String sql="delete from manager where id= ?";
		md.delManager(sql, manager);
	}

	@Override
	public void updateManager(Manager manager) {
		String sql="update manager set name=?,age=?,tel=?,email=?,passwd=?,pic=?,umanager=?,amanager=?,bmanager=?,rmanager=?,gmanager=?,nmanager=? where id=?";
		md.updateManager(sql, manager);
	}

	@Override
	public Manager queryManager(Manager manager) {
		String sql=" select id,name,age,tel,email,passwd,pic,umanager,amanager,bmanager,rmanager,gmanager,nmanager from manager where name= ? and passwd= ? ";
		return md.queryManager(sql,manager);
	}

	@Override
	public ArrayList<Manager> queryAllManager() {
		return null;
	}

	@Override
	public int CountAllManager() {
		String sql="select count(*) from manager";
		return md.CountAllManager(sql);
	}

	@Override
	public ArrayList<Manager> FenyyeQuery(int page, int rows) {
		String sql="select id,name,age,tel,email,passwd,pic,umanager,amanager,bmanager,rmanager,gmanager,nmanager from manager limit ?,?";
		return md.FenyyeQuery(sql, page, rows);
	}

	@Override
	public boolean isEnter(Manager manager) {
		String sql=" select name,passwd from manager where name= ? and passwd= ? ";
		//System.out.println(sql+"---------------ln 57");
		return md.isEnter(sql,manager);
	}

	@Override
	public Manager queryManagerById(Manager ma) {
		String sql=" select id,name,age,tel,email,passwd,pic,umanager,amanager,bmanager,rmanager,gmanager,nmanager from manager where id= ? ";
		return md.queryManagerById(sql,ma);
	}

	@Override
	public void updateManagerPicById(Manager m) {
		
		String sql="update manager set pic=? where id=?";
		md.updateManagerPicById(sql,m);
	}

	@Override
	public int CountManagerByEmail(Manager manager) {
		String sql="select count(*) from manager where email like '%"+manager.getEmail()+"%'";
		return md.CountAllManager(sql);
	}

	@Override
	public int CountManagerByTel(Manager manager) {
		String sql="select count(*) from manager where tel like '%"+manager.getTel()+"%'";
		return md.CountAllManager(sql);
	}

	@Override
	public int CountManagerByName(Manager manager) {
		String sql="select count(*) from manager where name like '%"+manager.getName()+"%'";
		return md.CountAllManager(sql);
	}

	@Override
	public int countManagerById(Manager manager) {
		String sql="select count(*) from manager where id like '%"+manager.getId()+"%'";
		return md.CountAllManager(sql);
	}

	@Override
	public ArrayList<Manager> FenyeQueryByTel(int nowPage, int pageRowNum,
			Manager manager) {
		String sql="select id,name,age,tel,email,passwd,pic,umanager,"
				+ "amanager,bmanager,rmanager,gmanager,nmanager "
				+ "from manager where tel like '%"+manager.getTel()+"%'"
				+ " limit ?,?";
		return md.FenyyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<Manager> FenyeQueryById(int nowPage, int pageRowNum,
			Manager manager) {
		String sql="select id,name,age,tel,email,passwd,pic,umanager,"
				+ "amanager,bmanager,rmanager,gmanager,nmanager "
				+ "from manager where id like '%"+manager.getId()+"%'"
				+ " limit ?,?";
		return md.FenyyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<Manager> FenyeQueryByEmail(int nowPage, int pageRowNum,
			Manager manager) {
		String sql="select id,name,age,tel,email,passwd,pic,umanager,"
				+ "amanager,bmanager,rmanager,gmanager,nmanager "
				+ "from manager where email like '%"+manager.getEmail()+"%'"
				+ " limit ?,?";
		return md.FenyyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<Manager> FenyeQueryByname(int nowPage, int pageRowNum,
			Manager manager) {
		String sql="select id,name,age,tel,email,passwd,pic,umanager,"
				+ "amanager,bmanager,rmanager,gmanager,nmanager "
				+ "from manager where name like '%"+manager.getName()+"%'"
				+ " limit ?,?";
		return md.FenyyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public void updateManagerPassword(Manager manager) {
		String sql="update manager set passwd=? where id=?";
		md.updateManagerPasswd(sql,manager);
	}

}
